package Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import Bean.Student;
import Dao.StudentDao;

public class ShowAllStudentServlet extends HttpServlet {

		
		public void doGet(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {

			ArrayList studentList = new ArrayList();
			StudentDao studentDao = new StudentDao();
			ServletContext application=this.getServletContext();
			try {
				studentList = studentDao.queryAllStudent();
				request.setAttribute("studentList", studentList);
				application.getRequestDispatcher("/showAllStudent.jsp").forward(request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		
		public void doPost(HttpServletRequest request, HttpServletResponse response)
				throws ServletException, IOException {

			String id = request.getParameter("stuid");
			Student student = new Student();
			StudentDao studentDao = new StudentDao();
			ServletContext application=this.getServletContext();
			try {
				student = studentDao.queryStudentById(id);
				ArrayList studentList = new ArrayList();
				studentList.add(student);
				request.setAttribute("studentList", studentList);
				application.getRequestDispatcher("/showAllStudent.jsp").forward(request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
			
		}
		



}
